#include <QFileDialog>

#include "AnAdbchoseDialog.h"
#include "AnGlobal.h"
#include "AnAdbServer.h"

AnAdbchoseDialog::AnAdbchoseDialog(QWidget *parent) : QDialog(parent)
{
    dia = new Ui::adbchosedialog();
    dia->setupUi(this);
    this->setWindowModality(Qt::ApplicationModal);

    QObject::connect(dia->exitButton, SIGNAL(clicked()),
                     this, SLOT(exitProg()));
    QObject::connect(dia->adbFileChoseButton, SIGNAL(clicked()),
                     this, SLOT(adbFileChose()));
    QObject::connect(dia->yesButton, SIGNAL(clicked()),
                     this, SLOT(yesCheck()));


    //adb_chose_path = "";
}


void AnAdbchoseDialog::exitProg()
{
    app->exit();
}

void AnAdbchoseDialog::adbFileChose()
{
    QString adb_tmp_path = QFileDialog::getOpenFileName(this, "选择Adb文件", ".");

    if (!adb_tmp_path.isNull()) {
        adb_chose_path = adb_tmp_path;
        dia->adbFileDisplayLabel->setText("路径：" + adb_chose_path);
    }
}

void AnAdbchoseDialog::yesCheck()
{
    //adb_path = adb_chose_path;
    emit sendYesCheck(adb_chose_path);
    //this->close();
    this->hide();
}


void AnAdbchoseDialog::showEvent(QShowEvent *event)
{
    adb_chose_path = adb_path;
    dia->adbFileDisplayLabel->setText("路径：" + adb_chose_path);
    QDialog::showEvent(event);
}

void AnAdbchoseDialog::closeEvent(QCloseEvent *event)
{
    app->exit();
}


